"""
# -*- coding: utf-8 -*-
# @Time    : 2023/5/23 8:27
# @Author  : 王摇摆
# @FileName: Visual.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.font_manager import FontProperties
from RandomForest.Regression.Data import X, y
from RandomForest.Regression.Train import rf

# 指定中文字体文件的路径
font_path = 'C:\Windows\Fonts\simkai.ttf'
# 加载中文字体
font = FontProperties(fname=font_path)

fig, ax = plt.subplots()
ax.set_facecolor('#f8f9fa')

x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
xx = np.arange(x_min, x_max, .05)
yy = rf.predict(np.c_[xx.ravel()])

plt.scatter(X, y, c='#e63946', marker='o', s=20)
plt.plot(xx, yy)

ax.set_title('随机森林回归', color='#264653', fontproperties=font, fontsize=16)
ax.set_xlabel('X', color='#264653')
ax.set_ylabel('Y', color='#264653')
ax.tick_params(labelcolor='#264653')
print('随机森林分类器已预测完毕！')
plt.show()
